from urllib import request, response
import time
import json


class LeCai():
    # "http://www.lecai.com/lottery/draw/sorts/ajax_get_draw_data.php?lottery_type=200&date=2017-06-04"
    url = r"http://www.lecai.com/lottery/draw/sorts/ajax_get_draw_data.php?lottery_type=200&date={date}"
    date = '2017-6-4'
    header = {}
    response = None

    def __init__(self):
        self.date = time.strftime("%Y-%m-%d")
        self.url = self.url.format(date=self.date)
        self.header['X-Requested-With'] = r"XMLHttpRequest";
        self.header['Referer'] = r"http://www.lecai.com/lottery/draw/view/200";
        self.header[
            'User-Agent'] = r"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.104 Safari/537.36 Core/1.53.2669.400 QQBrowser/9.6.10990.400";

    def collection(self):
        req = request.Request(self.url)

        for k in self.header:
            req.add_header(k, self.header[k])

        self.response = request.urlopen(req)
        data = self.response.read()
        print(json.loads(data.decode("utf-8")))

lecai = LeCai()
lecai.collection()
